﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using System.Web.Http;
using System.Web.Mvc;

using ERPStore.Extensions;
using ERPStore.Web.Routing;

using Microsoft.Practices.Unity;

using EventBrokR;

namespace ERPStore.Web.Exporter
{
    public class PluginInit : ERPStore.Exporter.PluginInit
    {
		public override void AddServices()
		{
			base.AddServices();

			if (ERPStore.GlobalConfiguration.Configuration.HosterName == "WebApp")
			{
				// EventConsumer
				var eb = Container.Resolve<EventBrokR.IPublisher>();
				eb.Container.Register<EventConsumers.NetAffTrackerOrderCreatedEventConsumer>();
			}
		}
		public override void RegisterRoutes()
		{
			var namespaces = new string[] { "ERPStore.Web.Exporter.Controllers" };

			RouteTable.Routes.MapHttpRoute(
				"AdminExporterApi"
				, "api/exporter/admin/{action}/{id}"
				, new { controller = "AdminExporterApi", action = "Ping", id = UrlParameter.Optional }
				);

			RouteTable.Routes.MapHttpRoute(
				"ExporterApi"
				, "api/exporter/{action}/{id}"
				, new { controller = "ExporterApi", action = "Ping", id = UrlParameter.Optional }
			);

			RouteTable.Routes.MapHttpRoute(
				"ShopzillaApi"
				, "api/shopzilla/{action}/{id}"
				, new { controller = "ShopzillaApi", action = string.Empty, id = UrlParameter.Optional }
			);

			RouteTable.Routes.MapRoute(
				"ExportFile"
				, "sitemaps/{*file}"
				, new { controller = "Exporter", action = "Download", file = UrlParameter.Optional }
				);

			RouteTable.Routes.MapRoute(
				"ComparatorTrackerRedirect"
				, "cp/trk/target"
				, new { Controller = "Exporter", action = "RedirectToTarget" }
				);

			RouteTable.Routes.MapRoute(
				"ComparatorTracker"
				, "cp/trk/{*key}"
				, new { controller = "Exporter", action = "TrackerRedirect", key = UrlParameter.Optional }
				);

		}

    }
}
